package freemarker;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.view.freemarker.FreeMarkerView;

public class ManagementFreeMarkerView extends FreeMarkerView{
    private static final String STATIC_PATH = "stx";
    private static final String MVC_PATH = "mvc_ctx";
    
    private static String saticPath = null;
    
    private static String contextPath = null;
    
    private static String mvcPath = null;
    
    /**
	 * 部署路径属性名称：webRoot
	 */
	public static final String CONTEXT_PATH = "webRoot";

    @SuppressWarnings({ "unchecked" })
    @Override
    protected void exposeHelpers(Map model, HttpServletRequest request) throws Exception {
        super.exposeHelpers(model, request);
        String ctx = request.getContextPath();
        String srp = ctx + "/static";
		if (saticPath == null) {
			saticPath = srp;
		}
		if(contextPath == null){
			contextPath = ctx;
		}
		String mvcURL=ctx + "/ftl";
		if(mvcPath == null){
			mvcPath = mvcURL;
		}
        model.put(STATIC_PATH, srp);
        model.put(MVC_PATH, mvcURL);
        String view = request.getParameter("viewMode");
        if ("true".equals(view)) {
            model.put("viewMode", true);
        }
        // 设置当前Request的来源地址
        model.put("REQUEST_REFERER", request.getHeader("REFERER"));
        model.put(CONTEXT_PATH, request.getContextPath());
    };


	public static String getStaticRootPath() {
		return saticPath;
	}
	
	public static String getContextPath() {
		return contextPath;
	}
	
	public static String getMVCPath() {
		return mvcPath;
	}
	
}
